/*
Realistic Unit Modification v4.0 Dialog 
v4.0.0.1 [ALPHA]
Concept & Development by Draper & Raps | [VRC]
*/

if (!("ItemMap" in items player)) then {
	player addItem "ItemMap";
	player assignItem "ItemMap";
};
if (isNil "RUM_ROE_nofire") then {
	RUM_ROE_nofire = [];
};
if (isNil "RUM_COM_Callsign") then {
	RUM_COM_Callsign = "Reaper 23";
};
if (isNil "RUM_RADIO_MissionName") then {
	RUM_RADIO_MissionName = "Stratis Operations";
};
if (isNil "RUM_RADIO_AssetProvider") then {
	RUM_RADIO_MissionName = "TACCOM";
};
_nil = [] execVM RUM_PATH+"Common\ROEzone.sqf";

/* Defines the path to the Helicopter Functions */
_nil = [] execVM (RUM_PATH+"Common\RUM_Helo_Fn.sqf");

///////////////// EDIT ARTILLERY AT YOUR OWN PERIL /////////////////
if (!isNil "RUM_ArtyBatts") then {
	private ["_lead","_bat","_guns","_units"];
	RUM_Arty_serverfire = false;
	RUM_Arty_ServerScoot = [];
	if (isServer) then {
		nul = [] execVM (RUM_PATH+"Arty\executefiremission_server.sqf");
		nul = [] execVM (RUM_PATH+"Arty\serverScoot.sqf");
		{
			_bat = _x select 0;
			_lead = leader driver _bat;
			_units = units group _lead;

			_guns = [];
			{if!(vehicle _x in _guns)then{_guns = _guns + [vehicle _x]}} foreach units group driver _bat;
			{_x disableAI "TARGET";_x disableAI "AUTOTARGET";_x lock true;} foreach _guns;

			_bat setvariable ["ARTY_ONMISSION", false, true];
		} forEach RUM_ArtyBatts;
	};

	RUM_Arty_stype_howitzer=[];
	for [{_i = 0}, {_i < count RUM_Arty_class_howitzer}, {_i = _i + 2}] do {
		RUM_Arty_stype_howitzer = RUM_Arty_stype_howitzer + [RUM_Arty_class_howitzer select _i];
	};
	RUM_Arty_stype_mortar=[];
	for [{_i = 0}, {_i < count RUM_Arty_class_mortar}, {_i = _i + 2}] do {
		RUM_Arty_stype_mortar = RUM_Arty_stype_mortar + [RUM_Arty_class_mortar select _i];
	};
	RUM_Arty_stype_mlrs=[];
	for [{_i = 0}, {_i < count RUM_Arty_class_mlrs}, {_i = _i + 2}] do {
		RUM_Arty_stype_mlrs = RUM_Arty_stype_mlrs + [RUM_Arty_class_mlrs select _i];
	};
	RUM_Arty_disstg = 0;
	RUM_Arty_dirstg = 0;
	RUM_Arty_updnstg = 0;
	RUM_Arty_totstg = 0;
	RUM_Arty_typeid = 0;
	RUM_Arty_typRid = 0;
	RUM_Arty_numRid = 0;
	RUM_Arty_timeid = 0;
	RUM_Arty_battid = 0;
	RUM_Arty_mtarid2 = 0;
	RUM_Arty_dispid = 0;
	RUM_Arty_ctarid = 0;
	RUM_Arty_colorcount = 0;
	RUM_Arty_tarpos = [0,0,0];
	RUM_updn = 0;
	RUM_dir=0;
	[] execVM (RUM_PATH+"Arty\RUM_Arty_Fn.sqf");
};
///////////////// END ARTILLERY

///////////////// EDIT FIXED WING AT YOUR OWN PERIL /////////////////
if (!isNil "RUM_FXDAircraft") then {
	private ["_arry","_plane","_stg"];
	RUM_FXD_idleorstation = true;
	for [{_n=1},{_n<=(count RUM_FXDAircraft)},{_n=_n+1}] do {
		_arry = RUM_FXDAircraft select (_n-1);
		_plane = _arry select 0;
		_stg = format ["%1",_plane];
		_plane setVehicleVarName _stg;
		_plane lock true;
		removeAllweapons _plane;
		{_plane removeMagazine _x} forEach magazines _plane;
		_plane setVariable ["RUM_inFlight", false, true];
		if (RUM_FXD_Rspwn) then {
			[_plane, RUM_FXD_RspwnTime, 30, RUM_FXD_NumRspwn, true, false, "this lock true;"] execVM (RUM_PATH+"Common\vehicle_respawn.sqf");
		} else {
			_plane addEventHandler ["killed",{_this execVM (RUM_PATH+"Fxd\planeDown.sqf");}];
		};
	};
	[] execVM (RUM_PATH+"Fxd\RUM_Fxd_codesnippets.sqf");
};
if (!isNil "RUM_FXDAircraft_onStation") then {
	{_x execVM (RUM_PATH+"Fxd\onStation_init.sqf")} forEach RUM_FXDAircraft_onStation;
};
//////////////// END FIXED WING

///////////////// EDIT ATTACK HELO AT YOUR OWN PERIL /////////////////
if (!isNil "RUM_AHelAircraft") then{
	private ["_arry","_helo","_stg"];
	if (isServer) then {
		// nul = [] execVM (RUM_PATH+"AHel\ServerMove.sqf");
		// nul = [] execVM (RUM_PATH+"AHel\ServerGunFire.sqf");
	};
	// helps with pda load animation
	RUM_AHEL_idleorstation = true;
	RUM_AHel_ATGM = false;
	RUM_AHel_SFS = false;
	for [{_n = 1},{_n <= (count RUM_AHelAircraft)},{_n = _n + 1}] do {
		_arry = RUM_AHelAircraft select (_n-1);
		_helo = _arry select 0;
		_stg = format ["%1",_helo];
		_helo setVehicleVarName _stg;
		if (RUM_AHEL_DriverGunnerLock) then {
			_helo lock true;
		};
		_helo setVariable ["RUM_inFlight", false, true];
		if (RUM_AHEL_Rspwn) then {
			[_helo, RUM_AHel_RspwnTime, RUM_AHEL_RspwnDesTime, RUM_AHel_NumRspwn, RUM_AHEL_RspwnDestroy, false, "this lock true;"] execVM (RUM_PATH+"Common\vehicle_respawn.sqf");
		} else {
			_helo addEventHandler ["killed",{_this execVM (RUM_PATH+"AHel\heloDown.sqf");}];
		};
	};
	[] execVM (RUM_PATH+"AHel\RUM_Helo_Fn.sqf");
};
if (!isNil "RUM_AHelAircraft_onStation") then {
	{_x execVM (RUM_PATH+"AHel\onStation_init.sqf")} forEach RUM_AHelAircraft_onStation;
};
//////////////// END ATTACK HELO

///////////////// EDIT TRANSPORT HELO AT YOUR OWN PERIL /////////////////
RUM_THel_choplist = [];
if (!isNil "RUM_THelAircraft") then {
	private ["_arry","_helo","_stg","_cfg"];
	
	for [{_n = 1},{_n <= (count RUM_THelAircraft)},{_n = _n + 1}] do {
		_arry = RUM_THelAircraft select (_n - 1);
		_helo = _arry select 0;
		_stg = format ["%1",_helo];
		_helo setVehicleVarName _stg;
		if (RUM_THEL_DriverLock) then {
			// _helo lockDriver true;
		};
		if (RUM_THEL_TurretLock) then {
			_cfg=configFile >> "CfgVehicles" >> typeof _helo >> "turrets";
			for [{_t=1},{_t<=count _cfg},{_t=_t+1}] do {
				// _helo lockTurret [[(_t-1)], true];
			};
		};
		_helo setVariable ["RUM_inFlight", false, true];
		if (RUM_THEL_Rspwn) then {
			[_helo, RUM_THel_RspwnTime, RUM_THel_RspwnDesTime, RUM_THel_NumRspwn, RUM_THel_RspwnDestroy, false, "this lockDriver true;"] execVM (RUM_PATH+"Common\vehicle_respawn.sqf");
		} else {
			_helo addEventHandler ["killed",{_this execVM (RUM_PATH+"Transport\heloDown.sqf");}];
		};
		RUM_THel_choplist = RUM_THel_choplist + [_helo];
	};
};
//////////////// END TRANSPORT HELO

///////////////// EDIT SUPPLY AT YOUR OWN PERIL /////////////////
if (!isNil "RUM_SUPAircraft") then {
	private ["_arry","_helo","_stg","_cfg"];
	for [{_n = 1},{_n <= (count RUM_SUPAircraft)},{_n = _n + 1}] do {
		_arry = RUM_SUPAircraft select (_n - 1);
		_helo = _arry select 0;
		if (!(_helo in RUM_THel_choplist)) then {
			_stg = format ["%1",_helo];
			_helo setVehicleVarName _stg;
			_helo lockDriver true;
			_cfg=configFile >> "CfgVehicles" >> typeof _helo >> "turrets";
			for [{_t = 1},{_t <= count _cfg},{_t = _t + 1}] do {
				_helo lockTurret [[(_t - 1)], true];
			};
			_helo setVariable ["RUM_inFlight", false, true];
			if (RUM_SUP_Rspwn) then {
				[_helo, RUM_SUP_RspwnTime, 30, RUM_SUP_NumRspwn, true, false, "this lockDriver true;"] execVM (RUM_PATH+"Common\vehicle_respawn.sqf");
			}else{
				_helo addEventHandler ["killed",{_this execVM (RUM_PATH+"Supply\heloDown.sqf");}];
			};
		};
	};
	// [] execVM (RUM_PATH+"Supply\RUM_Helo_Fn.sqf");
};
//////////////// END SUPPLY

/////////////// COMMMON FUNCTIONS ///////////////
varStancePos = getposATL player;
RUM_fn_ppEffect_dialog = {
	5 fadeSound .4;
	rum_PDA_blur = ppEffectCreate ["dynamicBlur", 454];
	rum_PDA_blur ppEffectEnable true;
	rum_PDA_blur ppEffectAdjust [2];
	rum_PDA_blur ppEffectCommit 1.5;
	if (stance player == "STAND") then {
		player playMoveNow "AmovPercMstpSlowWrflDnon_AmovPknlMstpSlowWrflDnon";
		varStancePos = getposATL player;
		sleep 0.75;
	} else {
		if ((stance player == "CROUCH")) then {
			if (!(round (varStancePos select 0) == round (getpos player select 0) && round (varStancePos select 1) == round (getpos player select 1))) then {
				player playMoveNow "amovpknlmstpsraswrfldnon_amovpknlmstpSlowwrfldnon";
				varStancePos = getPosATL player;
				sleep 0.75;
			};
		};
	};
	sleep 0.075;
};

RUM_fn_ppEffect_dialogDestroy = {
	5 fadeSound 1;
	ppEffectDestroy rum_PDA_blur;
};
/////////////////////////////////////////////////

if (true) exitWith {};
